import { gql } from '@apollo/client';
import { withApollo, graphql } from '@apollo/client/react/hoc';
import { compose } from 'recompose';
import dayjs from 'dayjs';
import viewstateHoc from '@kuiper-components/viewstate-hoc';

// eslint-disable-next-line
const startTime = dayjs().subtract(61, 'days').toDate();
const endTime = new Date();

export default compose(
	withApollo,
	graphql(
		gql`
			query(
				$id: MongoID
				$taskType: EnumResultNumbersTaskType
				$target: String
				$dateRange: IResultNumberDateRange
			) {
				results: ResultNumbersMany(
					filter: {
						jobId: $id
						taskType: $taskType
						target: $target
						dateRange: $dateRange
					}
				) {
					_id
					target
					datetime
					normalNodeCount
					totalNodeCount
					aviliable {
						area
						totalTime
					}
				}
			}
		`,
		{
			options({ jobId, taskType, target }) {
				return {
					variables: {
						taskType,
						target,
						id: jobId,
						dateRange: {
							startTime,
							endTime,
						},
					},
				};
			},
		}
	),
	viewstateHoc()
);
